package com.wushi.yangjing;

import java.util.Date;

import javax.jws.WebService;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.octopus.yangj.customized.service.CustomizedEventService;

/*
 * result
 * 1: the input parameter is null;
 */

@WebService(endpointInterface = "com.wushi.yangjing.EventMgtInf")
public class EventMgtImp implements EventMgtInf {
	
	private static Log log = LogFactory.getLog(EventMgtImp.class);
	
	@Autowired
	private CustomizedEventService eventSer;

	public int setEventResult(String wgEventId, String eventResult,
			Date handleTime, String handleDpt, String preHandleImg,
			String postHandleImg) {
		log.info("Invoked WG web service...");
    	log.info("externalId=" + wgEventId);
    	log.info("eventResult=" + eventResult);
    	log.info("handleTime=" + handleTime);
    	log.info("handleDpt=" + handleDpt);
    	log.info("preHandleImg=" + preHandleImg);
    	log.info("postHandleImg=" + postHandleImg);
		int result = -1;
		if (StringUtils.isBlank(wgEventId))
			result = 1;
//		else if (eventResult == null || eventResult == "")
//			result = 2;
		else if (handleTime == null)
			result = 3;
//		else if (handleDpt == null || handleDpt == "")
//			result = 4;
//		else if (preHandleImg == null || preHandleImg == "")
//			result = 5;
//		else if (postHandleImg == null || postHandleImg == "")
//			result = 6;
		
		if(result < 0){
			try {
				result =  eventSer.setEventResult(wgEventId, eventResult, handleTime,
						handleDpt, preHandleImg, postHandleImg);
			} catch (Exception e) {
				e.printStackTrace();
				result = 7;
			}
		}
		log.info("Result=" + result);
		return result;
	}

}
